package com.rainbowelephant.fun.fitness;

import java.io.Serializable;
import java.util.ArrayList;



public class Trophies implements Serializable
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ArrayList<Trophy> trophies;

	public Trophies()
	{
		trophies = new ArrayList<Trophy>();
		trophies.add(new Marathon("Marathon Runner","Run 26 miles"));
		trophies.add(new WeightLoss("Getting Skinny","Lose 2% of your starting weight"));
		trophies.add(new WeightLoss2("Skin and Bones","Lose 5% of your starting weight"));
		//trophies.add(new Goal("Good Start","Achieve 1 of your set goals"));
		//trophies.add(new Goal2("Goal Crusher","Achieve 20 of your set goals"));
		trophies.add(new Workout("Gotta Start Somewhere","Complete 1 workout"));
		trophies.add(new Workout2("Getting it Done","Complete 20 workouts"));
		trophies.add(new Workout3("Future Olympian","Complete 100 workouts"));
		trophies.add(new Pedometer("Daily Dose","Walk 10000 steps in one day"));
		trophies.add(new Pedometer2("Who Needs a Car","Walk 500000 steps"));
		trophies.add(new Distance("Morning Jog","Run 1 mile"));
		trophies.add(new Distance2("Track Star","Run 100 miles"));
	}
	public void completion(Profile x)
	{
		for(Trophy t:trophies)
		{
			t.check(x);
		}
	}
}

abstract class Trophy implements Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	String title;
	String description;
	boolean completed=false;
	public Trophy(String name,String about)
	{
		title=name;
		description=about;
	}
	public boolean isCompleted()
	{
		return completed;
	}
	public String getTitle()
	{
		return title;
	}
	public String getDescription()
	{
		return description;
	}
	public abstract boolean check(Profile person);

}
class Marathon extends Trophy
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Marathon(String name,String about)
	{
		super(name,about);
	}
	public boolean check(Profile person)
	{
		if(completed)
			return completed;
		if (person.getMilesRan()>=26)
		{
			completed=true;
			return true;
		}
		else
			return false;
	}

}
class WeightLoss extends Trophy
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public WeightLoss(String name,String about)
	{
		super(name,about);
	}
	public boolean check(Profile person)
	{
		if(completed)
			return completed;
		if((person.getStartWeight()-person.getWeight())/person.getStartWeight()>=.05)
		{
			completed=true;
			return true;
		}
		return false;
	}
}
class WeightLoss2 extends Trophy
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public WeightLoss2(String name,String about)
	{
		super(name,about);
	}
	public boolean check(Profile person)
	{
		if(completed)
			return completed;
		if((person.getStartWeight()-person.getWeight())/person.getStartWeight()>=.1)
		{
			completed=true;
			return true;
		}
		return false;
	}
}
class Goal extends Trophy
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Goal(String name,String about)
	{
		super(name,about);
	}
	public boolean check(Profile person)
	{
		if(completed)
			return completed;
		//if completed goals>1 
		return false;
	}
}
class Goal2 extends Trophy
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Goal2(String name,String about)
	{
		super(name,about);
	}
	public boolean check(Profile person)
	{
		if(completed)
			return completed;
		//if completed goals >20 completed=true return true else return false
				return false;
	}
}
class Workout extends Trophy
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Workout(String name,String about)
	{
		super(name,about);
	}
	public boolean check(Profile person)
	{
		if(completed)
			return completed;

		if(person.getWorkoutsComplete()>1)
		{
			completed=true;
			return completed;
		}
		return false;
	}
}
class Workout2 extends Trophy
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Workout2(String name,String about)
	{
		super(name,about);
	}
	public boolean check(Profile person)
	{
		if(completed)
			return completed;
		if(person.getWorkoutsComplete()>20)
		{
			completed=true;
			return completed;
		}
		return false;
	}
}
class Workout3 extends Trophy
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Workout3(String name,String about)
	{
		super(name,about);
	}
	public boolean check(Profile person)
	{
		if(completed)
			return completed;
		if(person.getWorkoutsComplete()>100)
		{
			completed=true;
			return completed;
		}
		return false;
	}
}
class Pedometer extends Trophy
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Pedometer(String name,String about)
	{
		super(name,about);
	}
	public boolean check(Profile person)
	{
		if(completed)
			return completed;
		//if walked 10000 steps completed=true return true else return false
				if(person.getStepsToday()>=10000)
				{
					completed=true;
					return completed;
				}
		return false;
	}
}
class Pedometer2 extends Trophy
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Pedometer2(String name,String about)
	{
		super(name,about);
	}
	public boolean check(Profile person)
	{
		if(completed)
			return completed;
		//if walked more than 500000 steps completed=true return true else return false
		if(person.getTotalSteps()>500000)
		{
			completed=true;
			return completed;
		}
		return false;
	}
}
class Distance extends Trophy
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Distance(String name,String about)
	{
		super(name,about);
	}
	public boolean check(Profile person)
	{
		if(completed)
			return completed;
		if(person.getMilesRan()>=1)
		{
			completed=true;
			return true;
		}
		return false;
	}
}
class Distance2 extends Trophy
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Distance2(String name,String about)
	{
		super(name,about);
	}
	public boolean check(Profile person)
	{
		if(completed)
			return completed;
		if(person.getMilesRan()>=100)
		{
			completed=true;
			return true;
		}
		else
			return false;
	}
}